<template>
  <view>
     <my-search @click.native="demo"></my-search>
    <view class="scroll-view">
      <!-- 左侧 -->
       <scroll-view scroll-y="true" :style="{height:wh +'px'}" class="scroll-left">
        <!-- <view class="scroll-view-item active" >1</view> -->
        <block v-for="(cate,index) in cateList" :key="index">
           <view :class="['scroll-view-item',index===active?'active':'']" @click="changeClass(index)">{{cate.cat_name}}</view>
        </block>
       </scroll-view>
       
       <!-- 右侧 -->
       <scroll-view scroll-y="true" :style="{height:wh +'px'}" class="scroll-right" :scroll-top="scrollTop">
     <view class="scroll-right-view" v-for="(cate2,index) in cateList2" :key="index">
      <view class="scroll-right-view-title">/{{cate2.cat_name}}/</view>
      <!-- 三级分类 -->
      <view class="scroll-right-cate3">
          <view class="scroll-right-cate3-item" v-for="(cate3,index) in cate2.children" :key="index" @click="goList(cate3)">
            <image :src="cate3.cat_icon"></image>
            <text>{{cate3.cat_name}}</text>
          </view>
      </view>
     </view>
       </scroll-view>
    </view>
  </view>
</template>

<script>
 import badgeMix from '@/mixins/tabbar-badge.js'
  export default {
      mixins:[ badgeMix ],
    data() {
      return {
        wh:0,
        cateList:[],
        cateList2:[],
        scrollTop:0,
        active:0
      };
    },
    onLoad(){
     const sysInfo =uni.getSystemInfoSync()
     this.wh = sysInfo.windowHeight-50
     this.getData()
    },
    methods:{
     async getData(){
        let {data:result} = await uni.$http.get('/api/public/v1/categories')
        if(result.meta.status!==200){
         return uni.$showMsg();
        }
        this.cateList = result.message
        this.cateList2 = result.message[0].children
        },
      changeClass(index){
        this.active = index;
        this.cateList2 = this.cateList[index].children
        this.scrollTop = this.scrollTop == 0 ? 1 : 0
      },
      demo(){
      uni.navigateTo({
        url:'/subpackage/search/search'
      })
      },
      goList(cate3){
        uni.navigateTo({
          url:"/subpackage/goods_list/goods_list?cid=" + cate3.cat_id
        }) 
      }
    }
  }
</script>

<style lang="scss">
.scroll-view{
  display:flex;
  .scroll-left{
    width:120px;
  }
  .scroll-view-item{
    background-color: #F7F7F7;
    line-height: 60px;
    text-align:center;
    font-size:12px;
    &.active {
      position: relative;
      background-color: #FFFFFF;
      &::before{
        content: "";
        display: block;
        width: 3px;
        height:30px;
        background-color: #C00000;
        position:absolute;
        top:50%;
        left:0;
        transform: translateY(-50%);
      }
    }
  }
  .scroll-right-view-title{
      font-size: 12px;
      font-weight: bold;
      text-align: center;
      padding: 15px 0;
  }
  .scroll-right-cate3{
    display: flex;
      flex-wrap: wrap;
    .scroll-right-cate3-item{
       width: 33.33%;
          margin-bottom: 10px;
          display: flex;
          flex-direction: column;
          align-items: center;
      image{
         width: 60px;
        height: 60px;
      }
      text{
         font-size: 12px;
      }
    }
  }
}
</style>
